#
# @lc app=leetcode.cn id=28 lang=python3
#
# [28] 实现 strStr()
#

# @lc code=start
class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        if needle =='':return 0
        heyLen = len(haystack)
        needLen = len(needle)
        if needLen > heyLen:return -1
        isMatch = True
        
        for i in range(heyLen):
            if (heyLen - i) < needLen: return -1
            if haystack[i] == needle[0]:
                for j in range(1,needLen):
                    if (i+j) >= heyLen or needle[j] != haystack[i+j]:
                        isMatch = False
                        break
                if isMatch:
                    return i
                else:
                    isMatch = True
  
        return -1
                    
            
                     
# @lc code=end

